import Vue from 'vue'
import Vuex from 'vuex'
import {getaddlist, getAllGalList, getAllList, selectALl} from "../api/api";

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    show:true,
    obj:{
      "fileType":'',
      "name":'',
      "startTime":'',
      "endTime":'',

    },
    visable:true,
    like:true,
    inforList:[],
    searchInforList:[],
    galleryList:[],
    searchGalList:[],
    productList:[],
    searchProList:[],
    datumList:[],
    pageSize:7,
    pageNum:1,
    total:"",
    Ptoytal:'',
    information:''
  },
  mutations: {
    //information页面的total
    changeTotal(content,payload){
      content.total = payload
    },
    changePTotal(content,payload){
      content.Ptotal = payload
    },
    // 列表与图形之间的转换
    changeShow(content,payload){
      content.show = payload
    },
    // 查询时输入的值
    changeObj(content,payload){
      content.obj = payload
    },
    changeVisable(content,payload){
      content.visable = payload
    },
    changeLike(content,payload){
      content.like = payload
    },
    // 获取资料查询数组
    changeInforList(content,payload){
      content.inforList = payload
    },
    changeSearchInforList(content,payload){
      content.searchInforList = payload
    },
    // 获取产品查询数组
    changeProList(content,payload){
      content.productList = payload
    },
    changeSearchProList(content,payload){
      content.searchProList = payload
    },
    // 获取图册查询数组
    changeGalList(content,payload){
      content.galleryList = payload
    },
    changeSearchGalList(content,payload){
      content.searchGalList = payload
    },
    // 获取数据的查询数组
    changeDatumList(content,payload){
      content.datumList = payload
    },

    changePageSize(content,payload){
      content.pageSize = payload
    },
    // 修改页数
    changePageNum(content,payload){
      content.pageNum = payload
    },
    // 传递图片信息
    changeInformation(content,payload){
      content.information=payload
    }
  },
  actions: {
    changeInforList(context){
       return getaddlist(1,7).then(res=>{
         console.log(this.$store.state.inforList)

        context.commit("inforList",res.page.list)
      })
    },
    changeSearchInforList(context){
      return getaddlist(1,18).then(res=>{
        console.log(this.$store.state.searchInforList)

        context.commit("searchInforList",res.page.list)
      })
    },
    changeProList(context){
      return getAllList(this.$store.state.pageNum,this.$store.state.pageSize).then(res=>{
        console.log(this.$store.state.productList)

        context.commit("productList",res.page.list)
      })
    },
    changeSearchProList(context){
      return getAllList(this.$store.state.pageNum,18).then(res=>{
        console.log(this.$store.state.productList)

        context.commit("searchProList",res.page.list)
      })
    },
    changeGalList(context){
      return getAllGalList(this.$store.state.pageNum,this.$store.state.pageSize).then(res=>{
        console.log(this.$store.state.galleryList)

        context.commit("galleryList",res.page.list)
      })
    },
    changeSearchGalList(context){
      return getAllGalList(this.$store.state.pageNum,18).then(res=>{
        console.log(this.$store.state.galleryList)

        context.commit("searchGalList",res.page.list)
      })
    },
    changeDatumList(context){
      return selectALl(this.$store.state.pageNum,this.$store.state.pageSize).then(res=>{
        context.commit("datumList",res.page.list)
      })
    },

  },
  modules: {
  }
})
